package com.lekang.system.service.impl;

import java.util.Date;
import java.util.List;
import com.lekang.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lekang.system.mapper.OrderManagementMapper;
import com.lekang.system.domain.OrderManagement;
import com.lekang.system.service.IOrderManagementService;

/**
 * 订单管理Service业务层处理
 * 
 * @author zhihao
 * @date 2025-10-15
 */
@Service
public class OrderManagementServiceImpl implements IOrderManagementService 
{
    @Autowired
    private OrderManagementMapper orderManagementMapper;

    /**
     * 查询订单管理
     * 
     * @param id 订单管理主键
     * @return 订单管理
     */
    @Override
    public OrderManagement selectOrderManagementById(Long id)
    {
        return orderManagementMapper.selectOrderManagementById(id);
    }

    /**
     * 查询订单管理列表
     * 
     * @param orderManagement 订单管理
     * @return 订单管理
     */
    @Override
    public List<OrderManagement> selectOrderManagementList(OrderManagement orderManagement)
    {
        return orderManagementMapper.selectOrderManagementList(orderManagement);
    }

    /**
     * 新增订单管理
     * 
     * @param orderManagement 订单管理
     * @return 结果
     */
    @Override
    public int insertOrderManagement(OrderManagement orderManagement)
    {
        orderManagement.setCreateTime(DateUtils.getNowDate());
        return orderManagementMapper.insertOrderManagement(orderManagement);
    }

    /**
     * 修改订单管理
     * 
     * @param orderManagement 订单管理
     * @return 结果
     */
    @Override
    public int updateOrderManagement(OrderManagement orderManagement)
    {
        orderManagement.setUpdateTime(DateUtils.getNowDate());
        return orderManagementMapper.updateOrderManagement(orderManagement);
    }

    /**
     * 批量删除订单管理
     * 
     * @param ids 需要删除的订单管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderManagementByIds(Long[] ids)
    {
        return orderManagementMapper.deleteOrderManagementByIds(ids);
    }

    /**
     * 删除订单管理信息
     * 
     * @param id 订单管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderManagementById(Long id)
    {
        return orderManagementMapper.deleteOrderManagementById(id);
    }



    @Override
    public int updateOrderStatusByThreeFields(
            Long elderlyId,
            Long nursingItemId,
            Date expectedServiceTime,
            String orderStatus,
            String transactionStatus
    ) {
        // 封装查询条件和待更新状态
        OrderManagement order = new OrderManagement();
        order.setElderlyId(elderlyId);
        order.setNursingItemId(nursingItemId);
        order.setExpectedServiceTime(expectedServiceTime);
        order.setOrderStatus(orderStatus);
        order.setTransactionStatus(transactionStatus);

        // 调用Mapper执行更新
        return orderManagementMapper.updateStatusByThreeFields(order);
    }
}
